package love.yuanmengrobot.wuziqi.Util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class GetPacksack {
    

    //获得背包信息
    public Packsack getPacksack(String userName){
        System.out.println("用户："+userName);
        Packsack packsack = new Packsack();
        packsack.setPropList(new ArrayList<Prop>());
        BaseDao baseDao = new BaseDao();
        String sql="select USERSCORE ,PROPNAME,PROPNUM ,PROPDESC FROM WUZIQIUSER,WUZIQIUSERPROPS,WUZIQIPROP WHERE WUZIQIUSER.USERID=WUZIQIUSERPROPS.USERID and WUZIQIUSERPROPS.PROPID=WUZIQIPROP.PROPID and WUZIQIUSER.USERNAME='"+userName+"'";
        ResultSet query = baseDao.query(sql);
        try{
            while (query.next()){
                Prop prop = new Prop();
                packsack.setUserscore(query.getLong("userScore"));
                prop.setPropName(query.getString("propName"));
                prop.setPropNum(query.getLong("propNum"));
                prop.setPropDesc(query.getString("propDesc"));
                packsack.getPropList().add(prop);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            baseDao.closeCon();
        }
        return packsack;
    }



    //获得今天赢得积分
    public Long getTodayScore(String userId){
        Long re=null;
        BaseDao baseDao = new BaseDao();
        String sql="select SUM(SCORE) from WUZIQISCORE WHERE TO_CHAR(scoreDate,'yyyy-mm-dd')=TO_CHAR(SYSDATE,'yyyy-mm-dd') and scoreSource=0 and USERID='"+userId+"'";
        ResultSet rs = baseDao.query(sql);
        try{
            if(rs.next()){
                return rs.getLong(1);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            baseDao.closeCon();
        }

        return re;
    }


}
